home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Collections: Camelot
/
Camelot 134 (1991-10)(Swedish User Group of Amiga)(SE)(PD)[WB].zip
/
Camelot 134 (1991-10)(Swedish User Group of Amiga)(SE)(PD)[WB].adf
/
RxSlides
/
open_pic.c
< prev
next >
Wrap
C/C++ Source or Header
|
1990-03-08
|
3KB
|
117 lines
/* :bk=0 */
/************************************************************************/
/* */
/* Open_pic.c */
/* */
/* Author: Lee M. Robertson, mods by Dean Bandes */
/* Based on an article in the Nov '86 Doctor Dobb's Journal */
/* by Mike Morton */
/* */
/************************************************************************/
#include "exec/types.h"
#include "exec/memory.h"
#include "graphics/gfx.h"
#include "fcntl.h"
#include "RxSlides.h"
#include "RxSliPic.h"
typedef unsigned long ID;
struct Chunk
{
ID ckID;
long ckSize;
};
#define MakeID(a,b,c,d) ( (long)(a)<<24 | (long)(b)<<16 | (long)(c)<<8 | (d) )
#define FORM MakeID('F','O','R','M')
#define ILBM MakeID('I','L','B','M')
#define LIST MakeID('L','I','S','T')
#define BODY MakeID('B','O','D','Y')
#define BMHD MakeID('B','M','H','D')
#define CMAP MakeID('C','M','A','P')
#define CSIZE sizeof(chunk)
#define BMHDSIZE sizeof( struct BitMapHeader)
/*---------------------------------------------------------------------------
* open_pic() -- open a picture file and initialize the picture data struct
*-------------------------------------------------------------------------*/
int open_pic( filename, pic )
char *filename; /* the picture file name */
register struct picture *pic; /* the picture data */
{
register int fd; /* the picture file descriptor */
struct Chunk chunk; /* temp for read data */
register int cmsize;
fd = open(filename, O_RDONLY); /* open the file */
if( fd == -1)
return (STS_NO_PIC_OPEN);
if( read(fd, (char *) &chunk, CSIZE) != CSIZE )
return (STS_READ_ERROR);
if( chunk.ckID != FORM)
return (STS_NOT_PICTURE);
/* check for ILBM file */
if( read(fd, (char *) &chunk, sizeof(long) ) != sizeof(long) )
return (STS_READ_ERROR);
if( chunk.ckID != ILBM )
return (STS_NOT_ILBM);
if( read(fd, (char *) &chunk, CSIZE) != CSIZE )
return (STS_READ_ERROR);
if( chunk.ckID != BMHD)
return (STS_BAD_BMHD);
if( chunk.ckSize != BMHDSIZE )
return (STS_BAD_BMHDSIZE);
/* read the BMHD data */
if( read( fd, (char *) &pic->bmhd, BMHDSIZE ) != BMHDSIZE )
return (STS_READ_ERROR);
pic->numcolors = 1; /* set default color map */
/* read chunks untill body is found */
while( read(fd, (char *) &chunk, CSIZE) == CSIZE )
{
if( chunk.ckID == CMAP)
{
/* read the color map */
/* get size of the color map */
if( chunk.ckSize > CMSIZE )
cmsize = CMSIZE;
else
cmsize = chunk.ckSize;
if( read(fd, &pic->cmap[0], cmsize ) != cmsize )
return (STS_READ_ERROR);
pic->numcolors = cmsize / 3; /* save # of colors in picture */
chunk.ckSize++;
chunk.ckSize &= ~1;
if( chunk.ckSize -= cmsize )
lseek( fd, chunk.ckSize, 1 ); /* skip rest of colormap */
}
if( chunk.ckID == BODY )
{
pic->bodysize = chunk.ckSize;
pic->fd = fd;
return (STS_OK); /* no errs */
}
/* else ignore this chunks data */
lseek(fd,chunk.ckSize,1);
}
}